package com.wtp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;

public class OrderActivity extends Activity implements OnClickListener, OnItemClickListener {

	ListView listView;
	OrderListAdapter adapter;
	RelativeLayout order_menu;
	LinearLayout order_serach;
	Button back,yb,serach_btn;
	LinearLayout db;
	int index = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_order);
		db = (LinearLayout) findViewById(R.id.db);
		yb = (Button) findViewById(R.id.yb);
		serach_btn = (Button) findViewById(R.id.serach_btn);
		back = (Button) findViewById(R.id.back);
		order_menu = (RelativeLayout) findViewById(R.id.order_menu);
		order_serach = (LinearLayout) findViewById(R.id.order_serach);

		listView = (ListView) findViewById(R.id.list);
		adapter = new OrderListAdapter(this, index,3,1);
		listView.setAdapter(adapter);

		db.setOnClickListener(this);
		yb.setOnClickListener(this);
		serach_btn.setOnClickListener(this);
		back.setOnClickListener(this);
		listView.setOnItemClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;
		case R.id.db:
			index = 1;
			adapter = new OrderListAdapter(this, index,3,1);
			listView.setAdapter(adapter);
			adapter.notifyDataSetChanged();
			db.setBackgroundResource(R.drawable.order_menu_button1_1);
			yb.setBackgroundResource(R.drawable.order_menu_button2);
			break;
		case R.id.yb:
			index = 2;
			adapter = new OrderListAdapter(this, index,1,1);
			listView.setAdapter(adapter);
			adapter.notifyDataSetChanged();
			db.setBackgroundResource(R.drawable.order_menu_button1);
			yb.setBackgroundResource(R.drawable.order_menu_button2_1);
			break;
		case R.id.serach_btn:
			Intent intent = new Intent(this, SerachActivity.class);
			startActivity(intent);
			break;
		default:
			break;
		}
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Intent intent = new Intent(this, WebActivity.class);
		if (index == 1) {
			if (arg2 == 0) {
				intent.putExtra("url", "file:///android_asset/web/ab.html");
			}else if (arg2 == 1) {
				intent.putExtra("url", "file:///android_asset/web/abc.html");
			}else if (arg2 == 2) {
				intent.putExtra("url", "file:///android_asset/web/abcd.html");
			}
		}else if (index == 2) {
			intent.putExtra("url", "file:///android_asset/web/yb.html");
		}
		
		startActivity(intent);
	}

}
